using Tycho.Parser.Tokens;

namespace Tycho.Parser.Peg {
    public class KeywordTerminal<Context> : Terminal<Context> {
        public string Identifier;

        public KeywordTerminal (string identifier) {
            Identifier = identifier;
        }

        protected override ParseResult<Context> ParseTerminal (Token[] tokens, int index, Context context) {
            Token token = tokens[index];
            if (token is IdentifierToken) {
                var id = token as IdentifierToken;
                if (id.Identifier == Identifier && id.ModulePath == null) {
                    return new ParseResult<Context> (index + 1, null, context);
                } else {
                    return null;
                }
            } else {
                return null;
            }
        }
    }
}